package com.gl.order.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gl.order.entity.OrderNumberInfo;
import com.gl.order.entity.TOrderLining;
import com.gl.order.entity.dto.LiningDto;
import com.gl.order.mapper.TOrderLiningMapper;
import com.gl.order.service.LiningService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: liangSY
 * @Date: 2021/6/26
 * @ClassName: LiningServiceImpl
 * @Description: LiningServiceImpl描述
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class LiningServiceImpl extends ServiceImpl<TOrderLiningMapper, TOrderLining> implements LiningService {

    @Override
    public void addLinings(String orderId,String orderNo,List<LiningDto> list) {
        if(CollectionUtil.isEmpty(list)){
            return;
        }
        List<TOrderLining> linings = new ArrayList<>();
        list.stream().forEach(lining -> {
            linings.add(TOrderLining.builder()
                    .cloth(lining.getCloth())
                    .process(lining.getProcess())
                    .color(lining.getColor())
                    .orderId(orderId)
                    .orderNo(orderNo)
                    .build());
        });
        saveBatch(linings);
    }

    @Override
    public List<TOrderLining> findByOrderId(String orderId) {
        LambdaQueryWrapper<TOrderLining> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TOrderLining::getOrderId,orderId);
        return list(queryWrapper);
    }

    @Override
    public void delByOrder(String orderId) {
        LambdaQueryWrapper<TOrderLining> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TOrderLining::getOrderId,orderId);
        remove(queryWrapper);
    }

    @Override
    public List<TOrderLining> getByOrderId(String orderId) {
        LambdaQueryWrapper<TOrderLining> queryWrapper =  Wrappers.lambdaQuery();
        queryWrapper.eq(TOrderLining::getOrderId,orderId);
        List<TOrderLining> list = list(queryWrapper);
        return list;
    }

}
